<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>页面转场动画 | East'blog</title><meta name="author" content="侯玉东"><meta name="copyright" content="侯玉东"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="页面转场动画">
<meta property="og:type" content="article">
<meta property="og:title" content="页面转场动画">
<meta property="og:url" content="https://houyudong1989.gitee.io/blog/2024/03/18/harmonyOS/%E5%8A%A8%E7%94%BB/index.html">
<meta property="og:site_name" content="East&#39;blog">
<meta property="og:description" content="页面转场动画">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg">
<meta property="article:published_time" content="2024-03-18T05:46:18.317Z">
<meta property="article:modified_time" content="2024-03-19T07:24:47.912Z">
<meta property="article:author" content="侯玉东">
<meta property="article:tag" content="harmonyOS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg"><link rel="shortcut icon" href="/blog/img/head.jpg"><link rel="canonical" href="https://houyudong1989.gitee.io/blog/2024/03/18/harmonyOS/%E5%8A%A8%E7%94%BB/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '页面转场动画',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-03-19 15:24:47'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (true) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/blog/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('/blog/img/library6.jpeg')"><nav id="nav"><span id="blog-info"><a href="/blog/" title="East'blog"><img class="site-icon" src="/blog/img/head.jpg"/><span class="site-name">East'blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">页面转场动画</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-03-18T05:46:18.317Z" title="发表于 2024-03-18 13:46:18">2024-03-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-03-19T07:24:47.912Z" title="更新于 2024-03-19 15:24:47">2024-03-19</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/harmonyOS/">harmonyOS</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="页面转场动画"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="动画概述"><a href="#动画概述" class="headerlink" title="动画概述"></a>动画概述</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">动画的原理是在一个时间段内，多次改变UI外观，由于人眼会产生视觉暂留，所以最终看到的就是一个“连续”的动画。UI的一次改变称为一个动画帧，对应一次屏幕刷新，而决定动画流畅度的一个重要指标就是帧率FPS（Frame Per Second），即每秒的动画帧数，帧率越高则动画就会越流畅。</span><br><span class="line">ArkUI中，产生动画的方式是改变属性值且指定动画参数。动画参数包含了如动画时长、变化规律（即曲线）等参数。当属性值发生变化后，按照动画参数，从原来的状态过渡到新的状态，即形成一个动画。</span><br><span class="line">ArkUI提供的动画能力按照页面的分类方式，可分为页面内的动画和页面间的动画。按照类型划分又分为帧动画、属性动画、显式动画、路径动画、转场动画。</span><br></pre></td></tr></table></figure>

<h2 id="帧动画"><a href="#帧动画" class="headerlink" title="帧动画"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-basic-components-imageanimator-0000001427584852-V3">帧动画</a></h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">帧动画也叫序列帧动画，其原理就是在时间轴的每帧上逐帧绘制不同的内容，使其连续播放而成动画。ArkUI开发框架提供了 ImageAnimator 组件实现帧动画能力,可以配置需要播放的图片列表，每张图片可以配置时长。</span><br></pre></td></tr></table></figure>

<h3 id="属性"><a href="#属性" class="headerlink" title="属性"></a>属性</h3><table>
<thead>
<tr>
<th align="left">参数名称</th>
<th align="left">参数类型</th>
<th align="left">参数描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">images</td>
<td align="left"><code>Array&lt;ImageFrameInfo&gt;</code></td>
<td align="left">设置图片帧信息集合。每一帧的帧信息(ImageFrameInfo)包含图片路径、图片大小、图片位置和图片播放时长信息，详见ImageFrameInfo属性说明。默认值：[]  不支持动态更新。</td>
</tr>
<tr>
<td align="left">state</td>
<td align="left">AnimationStatus</td>
<td align="left">默认为初始状态，用于控制播放状态。默认值：AnimationStatus.Initial</td>
</tr>
<tr>
<td align="left">duration</td>
<td align="left">number</td>
<td align="left">单位为毫秒，默认时长为1000ms；duration为0时，不播放图片；值的改变只会在下一次循环开始时生效；当images中任意一帧图片设置了单独的duration后，该属性设置无效。默认值：1000</td>
</tr>
<tr>
<td align="left">reverse</td>
<td align="left">boolean</td>
<td align="left">设置播放顺序。false表示从第1张图片播放到最后1张图片； true表示从最后1张图片播放到第1张图片。默认值：false</td>
</tr>
<tr>
<td align="left">fixedSize</td>
<td align="left">boolean</td>
<td align="left">设置图片大小是否固定为组件大小。 true表示图片大小与组件大小一致，此时设置图片的width 、height 、top 和left属性是无效的。false表示每一张图片的width 、height 、top和left属性都要单独设置。默认值：true</td>
</tr>
<tr>
<td align="left">preDecode^(deprecated)^</td>
<td align="left">number</td>
<td align="left">预解码的图片数量。例如该值设为2，则播放当前页时会提前加载后面两张图片至缓存以提升性能。从API version9开始废弃。默认值：0</td>
</tr>
<tr>
<td align="left">fillMode</td>
<td align="left">FillMode</td>
<td align="left">设置动画开始前和结束后的状态，可选值参见FillMode说明。默认值：FillMode.Forwards</td>
</tr>
<tr>
<td align="left">iterations</td>
<td align="left">number</td>
<td align="left">默认播放一次，设置为-1时表示无限次播放。默认值：1</td>
</tr>
</tbody></table>
<h3 id="ImageFrameInfo对象说明"><a href="#ImageFrameInfo对象说明" class="headerlink" title="ImageFrameInfo对象说明"></a>ImageFrameInfo对象说明</h3><table>
<thead>
<tr>
<th align="left">参数名称</th>
<th align="left">参数类型</th>
<th align="left">必填</th>
<th align="left">参数描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">src</td>
<td align="left">string,Resource</td>
<td align="left">是</td>
<td align="left">图片路径，图片格式为svg，png和jpg，从API Version9开始支持Resource类型的路径。</td>
</tr>
<tr>
<td align="left">width</td>
<td align="left">number   , string</td>
<td align="left">否</td>
<td align="left">图片宽度，默认值：0</td>
</tr>
<tr>
<td align="left">height</td>
<td align="left">number   ,string</td>
<td align="left">否</td>
<td align="left">图片高度，默认值：0</td>
</tr>
<tr>
<td align="left">top</td>
<td align="left">number   ,string</td>
<td align="left">否</td>
<td align="left">图片相对于组件左上角的纵向坐标。 默认值：0</td>
</tr>
<tr>
<td align="left">left</td>
<td align="left">number   ,string</td>
<td align="left">否</td>
<td align="left">图片相对于组件左上角的横向坐标。默认值：0</td>
</tr>
<tr>
<td align="left">duration</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">每一帧图片的播放时长，单位毫秒。默认值：0</td>
</tr>
</tbody></table>
<h3 id="事件"><a href="#事件" class="headerlink" title="事件"></a>事件</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">功能描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">onStart(event: () &#x3D;&gt; void)</td>
<td align="left">状态回调，动画开始播放时触发。</td>
</tr>
<tr>
<td align="left">onPause(event: () &#x3D;&gt; void)</td>
<td align="left">状态回调，动画暂停播放时触发。</td>
</tr>
<tr>
<td align="left">onRepeat(event: () &#x3D;&gt; void)</td>
<td align="left">状态回调，动画重复播放时触发。</td>
</tr>
<tr>
<td align="left">onCancel(event: () &#x3D;&gt; void)</td>
<td align="left">状态回调，动画取消播放时触发。</td>
</tr>
<tr>
<td align="left">onFinish(event: () &#x3D;&gt; void)</td>
<td align="left">状态回调，动画播放完成时触发。</td>
</tr>
</tbody></table>
<h3 id="FillMode"><a href="#FillMode" class="headerlink" title="FillMode"></a>FillMode</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">None</td>
<td align="left">动画未执行时不会将任何样式应用于目标，动画播放完成之后恢复初始默认状态。</td>
</tr>
<tr>
<td align="left">Forwards</td>
<td align="left">目标将保留动画执行期间最后一个关键帧的状态。</td>
</tr>
<tr>
<td align="left">Backwards</td>
<td align="left">动画将在应用于目标时立即应用第一个关键帧中定义的值，并在delay期间保留此值。第一个关键帧取决于playMode，playMode为Normal或Alternate时为from的状态，playMode为Reverse或AlternateReverse时为to的状态。</td>
</tr>
<tr>
<td align="left">Both</td>
<td align="left">动画将遵循Forwards和Backwards的规则，从而在两个方向上扩展动画属性。</td>
</tr>
</tbody></table>
<h3 id="AnimationStatus"><a href="#AnimationStatus" class="headerlink" title="AnimationStatus"></a>AnimationStatus</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">Initial</td>
<td align="left">动画初始状态。</td>
</tr>
<tr>
<td align="left">Running</td>
<td align="left">动画处于播放状态。</td>
</tr>
<tr>
<td align="left">Paused</td>
<td align="left">动画处于暂停状态。</td>
</tr>
<tr>
<td align="left">Stopped</td>
<td align="left">动画处于停止状态。</td>
</tr>
</tbody></table>
<h3 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Row</span>() &#123;</span><br><span class="line">     <span class="title class_">Column</span>() &#123;</span><br><span class="line">     <span class="title class_">ImageAnimator</span>().<span class="title function_">images</span>([</span><br><span class="line">       &#123;<span class="attr">src</span>:$r(<span class="string">&quot;app.media.startIcon&quot;</span>)&#125;,</span><br><span class="line">       &#123;<span class="attr">src</span>:$r(<span class="string">&quot;app.media.ic_tab_normal&quot;</span>)&#125;,</span><br><span class="line">       &#123;<span class="attr">src</span>:$r(<span class="string">&quot;app.media.ic_tab_activated&quot;</span>)&#125;,</span><br><span class="line">       &#123;<span class="attr">src</span>:$r(<span class="string">&quot;app.media.app_icon&quot;</span>)&#125;</span><br><span class="line">     ]).<span class="title function_">duration</span>(<span class="number">1000</span>).<span class="title function_">state</span>(<span class="variable language_">this</span>.<span class="property">state</span>).<span class="title function_">reverse</span>(<span class="variable language_">this</span>.<span class="property">reverse</span>).<span class="title function_">fillMode</span>(<span class="title class_">FillMode</span>.<span class="property">None</span>)</span><br><span class="line">       .<span class="title function_">iterations</span>(<span class="variable language_">this</span>.<span class="property">iterations</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">height</span>(<span class="number">100</span>)</span><br><span class="line">       .<span class="title function_">margin</span>(&#123; <span class="attr">top</span>: <span class="number">100</span> &#125;)</span><br><span class="line">       .<span class="title function_">onStart</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">         <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;动画开始执行&#x27;</span>)</span><br><span class="line">       &#125;)</span><br><span class="line">       .<span class="title function_">onPause</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">         <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;动画暂停&#x27;</span>)</span><br><span class="line">       &#125;)</span><br><span class="line">       .<span class="title function_">onRepeat</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">         <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;动画重新播放&#x27;</span>)</span><br><span class="line">       &#125;)</span><br><span class="line">       .<span class="title function_">onCancel</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">         <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;动画取消&#x27;</span>)</span><br><span class="line">       &#125;)</span><br><span class="line">       .<span class="title function_">onFinish</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">         <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;动画执行完毕&#x27;</span>)</span><br><span class="line">         <span class="variable language_">this</span>.<span class="property">state</span> = <span class="title class_">AnimationStatus</span>.<span class="property">Stopped</span></span><br><span class="line">       &#125;)</span><br><span class="line">       <span class="title class_">Row</span>() &#123;</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;开始&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">state</span> = <span class="title class_">AnimationStatus</span>.<span class="property">Running</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;暂停&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">state</span> = <span class="title class_">AnimationStatus</span>.<span class="property">Paused</span>     <span class="comment">// 显示当前帧图片</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;停止&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">state</span> = <span class="title class_">AnimationStatus</span>.<span class="property">Stopped</span>    <span class="comment">// 显示动画的起始帧图片</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       <span class="title class_">Row</span>() &#123;</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;反转&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">reverse</span> = !<span class="variable language_">this</span>.<span class="property">reverse</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;一次&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">iterations</span> = <span class="number">1</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">         <span class="title class_">Button</span>(<span class="string">&#x27;循环&#x27;</span>).<span class="title function_">width</span>(<span class="number">100</span>).<span class="title function_">padding</span>(<span class="number">5</span>).<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">iterations</span> = -<span class="number">1</span> <span class="comment">// 无限循环播放</span></span><br><span class="line">         &#125;).<span class="title function_">margin</span>(<span class="number">5</span>)</span><br><span class="line">       &#125;</span><br><span class="line">     &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h2 id="显式动画"><a href="#显式动画" class="headerlink" title="显式动画"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-explicit-animation-0000001478341181-V3">显式动画</a></h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">显式动画（animateTo） 是ArkUI提供的最基础和常用的动画功能。在布局属性（如尺寸属性、位置属性）发生变化时，可以通过显式动画，按照动画参数过渡到新的布局参数状态。</span><br><span class="line">特点：闭包内的变化均会触发动画，包括由数据变化引起的组件的增删、组件属性的变化等，可以做较为复杂的动画。</span><br></pre></td></tr></table></figure>

<ul>
<li>animateTo(value: AnimateParam, event: () &#x3D;&gt; void): void</li>
<li>显式动画作为独立函数调用，而属性动画作为控件的属性进行调用</li>
</ul>
<h3 id="属性-1"><a href="#属性-1" class="headerlink" title="属性"></a>属性</h3><table>
<thead>
<tr>
<th align="left">参数</th>
<th align="left">类型</th>
<th align="left">是否必填</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">value</td>
<td align="left">AnimateParam</td>
<td align="left">是</td>
<td align="left">设置动画效果相关参数。</td>
</tr>
<tr>
<td align="left">event</td>
<td align="left">() &#x3D;&gt; void</td>
<td align="left">是</td>
<td align="left">指定显示动效的闭包函数，在闭包函数中导致的状态变化系统会自动插入过渡动画。</td>
</tr>
</tbody></table>
<h3 id="AnimateParam对象说明"><a href="#AnimateParam对象说明" class="headerlink" title="AnimateParam对象说明"></a>AnimateParam对象说明</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">类型</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">duration</td>
<td align="left">number</td>
<td align="left">动画持续时间，单位为毫秒。默认值：1000从API version 9开始，该接口支持在ArkTS卡片中使用。<strong>说明：</strong>- 在ArkTS卡片上最大动画持续时间为1000毫秒，若超出则固定为1000毫秒。- 设置浮点型类型的值时，向下取整。例如，设置值为1.2，按照1处理。</td>
</tr>
<tr>
<td align="left">tempo</td>
<td align="left">number</td>
<td align="left">动画的播放速度，值越大动画播放越快，值越小播放越慢，为0时无动画效果。默认值：1.0</td>
</tr>
<tr>
<td align="left">curve</td>
<td align="left">Curve，ICurve，string</td>
<td align="left">动画曲线。默认值：Curve.EaseInOut  从API version 9开始，该接口支持在ArkTS卡片中使用。</td>
</tr>
<tr>
<td align="left">delay</td>
<td align="left">number</td>
<td align="left">单位为ms(毫秒)，默认不延时播放。默认值：0<strong>说明：</strong>- 设置浮点型类型的值时，向下取整。例如，设置值为1.2，按照1处理。</td>
</tr>
<tr>
<td align="left">iterations</td>
<td align="left">number</td>
<td align="left">默认播放一次，设置为-1时表示无限次播放。默认值：1</td>
</tr>
<tr>
<td align="left">playMode</td>
<td align="left"><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-appendix-enums-0000001478061741-V3#ZH-CN_TOPIC_0000001574248789__playmode">PlayMode</a></td>
<td align="left">设置动画播放模式，默认播放完成后重头开始播放。默认值：PlayMode.Normal从API version 9开始，该接口支持在ArkTS卡片中使用。相关使用约束请参考PlayMode说明。</td>
</tr>
<tr>
<td align="left">onFinish</td>
<td align="left">() &#x3D;&gt; void</td>
<td align="left">动效播放完成回调。从API version 9开始，该接口支持在ArkTS卡片中使用。</td>
</tr>
</tbody></table>
<h3 id="示例-1"><a href="#示例-1" class="headerlink" title="示例"></a>示例</h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@State</span> <span class="attr">btnwidth</span>:<span class="built_in">number</span> = <span class="number">200</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">btnheight</span>:<span class="built_in">number</span> = <span class="number">80</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">flag</span>:<span class="built_in">boolean</span> =<span class="literal">false</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">bgcolor</span>:<span class="title class_">Resource</span> =$r(<span class="string">&quot;app.color.tab_text_normal&quot;</span>)</span><br><span class="line"> <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">   <span class="title class_">Column</span>() &#123;</span><br><span class="line">     <span class="title class_">Button</span>(<span class="string">&#x27;改变按钮大小&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">       <span class="keyword">if</span>(<span class="variable language_">this</span>.<span class="property">flag</span>)&#123;</span><br><span class="line">         <span class="title function_">animateTo</span>(&#123;</span><br><span class="line">           <span class="attr">duration</span>:<span class="number">2000</span>,</span><br><span class="line">           <span class="attr">tempo</span>:<span class="number">.4</span>,</span><br><span class="line">           <span class="attr">delay</span>:<span class="number">100</span>,</span><br><span class="line">           <span class="attr">iterations</span>:<span class="number">2</span>,</span><br><span class="line">           <span class="attr">onFinish</span>:<span class="function">()=&gt;</span>&#123;</span><br><span class="line">             <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27; wancheng ...&#x27;</span>)</span><br><span class="line">           &#125;</span><br><span class="line">         &#125;,<span class="function">()=&gt;</span>&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">btnwidth</span> = <span class="number">80</span></span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">btnheight</span>= <span class="number">30</span></span><br><span class="line">         &#125;)</span><br><span class="line">       &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">         <span class="title function_">animateTo</span>(&#123;&#125;,<span class="function">()=&gt;</span>&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">btnwidth</span> = <span class="number">200</span></span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">btnheight</span> = <span class="number">80</span></span><br><span class="line">         &#125;)</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="variable language_">this</span>.<span class="property">flag</span> = !<span class="variable language_">this</span>.<span class="property">flag</span></span><br><span class="line">     &#125;).<span class="title function_">width</span>(<span class="variable language_">this</span>.<span class="property">btnwidth</span>).<span class="title function_">height</span>(<span class="variable language_">this</span>.<span class="property">btnheight</span>)</span><br><span class="line"></span><br><span class="line">     <span class="title class_">Button</span>(<span class="string">&#x27;改变按钮颜色&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line"></span><br><span class="line">       <span class="keyword">if</span>(<span class="variable language_">this</span>.<span class="property">flag</span>)&#123;</span><br><span class="line">         <span class="title function_">animateTo</span>(&#123;</span><br><span class="line">           <span class="attr">duration</span>:<span class="number">2000</span>,</span><br><span class="line">           <span class="attr">tempo</span>:<span class="number">.4</span>,</span><br><span class="line">           <span class="attr">delay</span>:<span class="number">100</span>,</span><br><span class="line">           <span class="attr">iterations</span>:<span class="number">2</span>,</span><br><span class="line">           <span class="attr">onFinish</span>:<span class="function">()=&gt;</span>&#123;</span><br><span class="line">             <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27; wancheng ...&#x27;</span>)</span><br><span class="line">           &#125;</span><br><span class="line">         &#125;,<span class="function">()=&gt;</span>&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">bgcolor</span> = $r(<span class="string">&quot;app.color.category_background&quot;</span>)</span><br><span class="line">         &#125;)</span><br><span class="line"></span><br><span class="line">       &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">         <span class="title function_">animateTo</span>(&#123;&#125;,<span class="function">()=&gt;</span>&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">bgcolor</span> = $r(<span class="string">&quot;app.color.tab_text_normal&quot;</span>)</span><br><span class="line">         &#125;)</span><br><span class="line"></span><br><span class="line">       &#125;</span><br><span class="line">       <span class="variable language_">this</span>.<span class="property">flag</span> = !<span class="variable language_">this</span>.<span class="property">flag</span></span><br><span class="line">     &#125;).<span class="title function_">width</span>(<span class="number">200</span>).<span class="title function_">height</span>(<span class="number">80</span>).<span class="title function_">backgroundColor</span>(<span class="variable language_">this</span>.<span class="property">bgcolor</span>).<span class="title function_">margin</span>(&#123;<span class="attr">top</span>:<span class="number">10</span>&#125;)</span><br><span class="line">  </span><br><span class="line">   &#125;</span><br><span class="line">   .<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">   .<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">justifyContent</span>(<span class="title class_">FlexAlign</span>.<span class="property">Center</span>)</span><br><span class="line">   .<span class="title function_">alignItems</span>(<span class="title class_">HorizontalAlign</span>.<span class="property">Center</span>)</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h2 id="属性动画"><a href="#属性动画" class="headerlink" title="属性动画"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-animatorproperty-0000001478181445-V3">属性动画</a></h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">属性动画（animation） 是ArkUI提供的最基础和常用的动画功能。 组件的某些通用属性变化时，可以通过属性动画实现渐变过渡效果，提升用户体验。支持的属性包括width、height、backgroundColor、opacity、scale、rotate、translate等。</span><br><span class="line">特点：动画设置简单，属性变化时自动触发动画。</span><br></pre></td></tr></table></figure>

<ul>
<li>animation(value: {duration?: number, tempo?: number, curve?: string | Curve | ICurve, delay?:number, iterations: number, playMode?: PlayMode, onFinish?: () &#x3D;&gt; void})</li>
<li>属性动画作为控件的属性进行调用，而显式动画作为独立函数调用</li>
</ul>
<h3 id="属性-2"><a href="#属性-2" class="headerlink" title="属性"></a>属性</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">参数类型</th>
<th align="left">必填</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">duration</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">设置动画时长。默认值：1000单位：毫秒从API version 9开始，该接口支持在ArkTS卡片中使用。<strong>说明：</strong>- 在ArkTS卡片上最大动画持续时间为1000毫秒。- 设置浮点型类型的值时，向下取整；设置值为1.2，按照1处理。</td>
</tr>
<tr>
<td align="left">tempo</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">动画播放速度。数值越大，动画播放速度越快，数值越小，播放速度越慢。值为0时，表示不存在动画。默认值：1</td>
</tr>
<tr>
<td align="left">curve</td>
<td align="left">string，Curve，ICurve</td>
<td align="left">否</td>
<td align="left">设置动画曲线。 默认值：Curve.EaseInOut 从API version 9开始，该接口支持在ArkTS卡片中使用。</td>
</tr>
<tr>
<td align="left">delay</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">设置动画延迟执行的时长。默认值：0，不延迟播放。单位：毫秒取值范围：[0, +∞)<strong>说明：</strong>设置浮点型类型的值时，向下取整。例如，设置值为1.2，按照1处理。</td>
</tr>
<tr>
<td align="left">iterations</td>
<td align="left">number</td>
<td align="left">否</td>
<td align="left">设置播放次数。默认值：1取值范围：[-1, +∞)<strong>说明：</strong>设置为-1时表示无限次播放。设置为0时表示无动画效果。</td>
</tr>
<tr>
<td align="left">playMode</td>
<td align="left"><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-appendix-enums-0000001478061741-V3#ZH-CN_TOPIC_0000001574248789__playmode">PlayMode</a></td>
<td align="left">否</td>
<td align="left">设置动画播放模式，默认播放完成后重头开始播放。默认值：PlayMode.Normal从API version 9开始，该接口支持在ArkTS卡片中使用。</td>
</tr>
<tr>
<td align="left">onFinish</td>
<td align="left">() &#x3D;&gt; void</td>
<td align="left">否</td>
<td align="left">状态回调，动画播放完成时触发。从API version 9开始，该接口支持在ArkTS卡片中使用。<strong>说明：</strong>当iterations设置为-1时，动画效果无限循环不会停止，所以不会触发此回调。</td>
</tr>
</tbody></table>
<h3 id="示例-2"><a href="#示例-2" class="headerlink" title="示例"></a>示例</h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@State</span> <span class="attr">btnwidth</span>:<span class="built_in">number</span> = <span class="number">200</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">btnheight</span>:<span class="built_in">number</span> = <span class="number">80</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">flag</span>:<span class="built_in">boolean</span> =<span class="literal">false</span></span><br><span class="line"> <span class="meta">@State</span> <span class="attr">bgcolor</span>:<span class="title class_">Resource</span> =$r(<span class="string">&quot;app.color.tab_text_normal&quot;</span>)</span><br><span class="line"> <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line"></span><br><span class="line">     <span class="title class_">Column</span>() &#123;</span><br><span class="line">        <span class="title class_">Button</span>(<span class="string">&#x27;改变按钮大小&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">          <span class="keyword">if</span>(<span class="variable language_">this</span>.<span class="property">flag</span>)&#123;</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">btnwidth</span> = <span class="number">80</span></span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">btnheight</span>= <span class="number">30</span></span><br><span class="line">          &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">btnwidth</span> = <span class="number">200</span></span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">btnheight</span> = <span class="number">80</span></span><br><span class="line">          &#125;</span><br><span class="line">          <span class="variable language_">this</span>.<span class="property">flag</span> = !<span class="variable language_">this</span>.<span class="property">flag</span></span><br><span class="line">        &#125;).<span class="title function_">width</span>(<span class="variable language_">this</span>.<span class="property">btnwidth</span>).<span class="title function_">height</span>(<span class="variable language_">this</span>.<span class="property">btnheight</span>)</span><br><span class="line">          .<span class="title function_">animation</span>(&#123;</span><br><span class="line">            <span class="attr">duration</span>:<span class="number">2000</span>,</span><br><span class="line">            <span class="attr">tempo</span>:<span class="number">.4</span>,</span><br><span class="line">            <span class="attr">delay</span>:<span class="number">100</span>,</span><br><span class="line">            <span class="attr">iterations</span>:<span class="number">2</span>,</span><br><span class="line">            <span class="attr">onFinish</span>:<span class="function">()=&gt;</span> &#123;</span><br><span class="line">              <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;执行完成&quot;</span>)</span><br><span class="line">            &#125;</span><br><span class="line">          &#125;)</span><br><span class="line">       <span class="title class_">Button</span>(<span class="string">&#x27;改变按钮颜色&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">         <span class="keyword">if</span>(<span class="variable language_">this</span>.<span class="property">flag</span>)&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">bgcolor</span> = $r(<span class="string">&quot;app.color.category_background&quot;</span>)</span><br><span class="line">         &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">           <span class="variable language_">this</span>.<span class="property">bgcolor</span> = $r(<span class="string">&quot;app.color.tab_text_normal&quot;</span>)</span><br><span class="line">         &#125;</span><br><span class="line">         <span class="variable language_">this</span>.<span class="property">flag</span> = !<span class="variable language_">this</span>.<span class="property">flag</span></span><br><span class="line">       &#125;).<span class="title function_">width</span>(<span class="number">200</span>).<span class="title function_">height</span>(<span class="number">80</span>).<span class="title function_">backgroundColor</span>(<span class="variable language_">this</span>.<span class="property">bgcolor</span>).<span class="title function_">margin</span>(&#123;<span class="attr">top</span>:<span class="number">10</span>&#125;)</span><br><span class="line">         .<span class="title function_">animation</span>(&#123;</span><br><span class="line">           <span class="attr">duration</span>:<span class="number">2000</span>,</span><br><span class="line">           <span class="attr">tempo</span>:<span class="number">.4</span>,</span><br><span class="line">           <span class="attr">delay</span>:<span class="number">100</span>,</span><br><span class="line">           <span class="attr">iterations</span>:<span class="number">2</span>,</span><br><span class="line">           <span class="attr">onFinish</span>:<span class="function">()=&gt;</span> &#123;</span><br><span class="line">             <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;执行完成&quot;</span>)</span><br><span class="line">           &#125;</span><br><span class="line">         &#125;)</span><br><span class="line">     &#125;</span><br><span class="line">     .<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">   .<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">justifyContent</span>(<span class="title class_">FlexAlign</span>.<span class="property">Center</span>)</span><br><span class="line">     .<span class="title function_">alignItems</span>(<span class="title class_">HorizontalAlign</span>.<span class="property">Center</span>)</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>

<h2 id="路径动画"><a href="#路径动画" class="headerlink" title="路径动画"></a><a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-references-V3/ts-motion-path-animation-0000001427584908-V3">路径动画</a></h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">设置组件进行位移动画时的运动路径。</span><br></pre></td></tr></table></figure>

<h3 id="属性-3"><a href="#属性-3" class="headerlink" title="属性"></a>属性</h3><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">参数</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">motionPath</td>
<td align="left">{path: string,from?: number,to?: number,rotatable?: boolean}</td>
<td align="left">设置组件的运动路径。- path：位移动画的运动路径，使用svg路径字符串。path中支持使用start和end进行起点和终点的替代，如：’Mstart.x start.y L50 50 Lend.x end.y Z’，更多说明请参考<a target="_blank" rel="noopener" href="https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/ui-js-components-svg-path-0000001427584700-V3">绘制路径</a>。- from：运动路径的起点。取值范围：[0, 1]- to：运动路径的终点。取值范围：[0, 1]- rotatable：是否跟随路径进行旋转。</td>
</tr>
</tbody></table>
<ul>
<li>path: ‘Mstart.x start.y L300 200 L300 500 Lend.x end.y’</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">*说明</span><br><span class="line">M/m = moveto 参数x和y表示需要移动到点的x轴和y轴的坐标。在使用M命令移动画笔后，只会移动画笔，但不会在两点之间画线。所以M命令经常出现在路径的开始处，用来指明从何处开始画。</span><br><span class="line"></span><br><span class="line">L/l = lineto 参数x和y表示一个点的x轴和y轴坐标，L命令将会在当前位置和新位置（L前面画笔所在的点）之间画一条线段。</span><br><span class="line"></span><br><span class="line">H/h = horizontal lineto 绘制平行线。</span><br><span class="line"></span><br><span class="line">V/v = vertical lineto 绘制垂直线。</span><br><span class="line"></span><br><span class="line">C/c = curveto 三次贝塞尔曲线 设置三组坐标参数： x1 y1, x2 y2, x y。</span><br><span class="line"></span><br><span class="line">S/s = smooth curveto 三次贝塞尔曲线命令 设置两组坐标参数： x2 y2, x y。</span><br><span class="line"></span><br><span class="line">Q/q = quadratic <span class="title class_">Belzier</span> curve 二次贝塞尔曲线 设置两组坐标参数： x1 y1, x y。</span><br><span class="line"></span><br><span class="line">T/t = smooth quadratic <span class="title class_">Belzier</span> curveto 二次贝塞尔曲线命令 设置参数： x y。</span><br><span class="line"></span><br><span class="line">A/a = elliptical <span class="title class_">Arc</span> 弧形命令 设置参数： rx ry x-axis-rotation（旋转角度）large-arc-flag（角度大小） sweep-flag（弧线方向） x y。large-arc-flag决定弧线是大于还是小于<span class="number">180</span>度，<span class="number">0</span>表示小角度弧，<span class="number">1</span>表示大角度弧。sweep-flag表示弧线的方向，<span class="number">0</span>表示从起点到终点沿逆时针画弧，<span class="number">1</span>表示从起点到终点沿顺时针画弧。</span><br><span class="line"></span><br><span class="line">Z/z = closepath 从当前点画一条直线到路径的起点。</span><br></pre></td></tr></table></figure>

<h3 id="示例-3"><a href="#示例-3" class="headerlink" title="示例"></a>示例</h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@State</span> <span class="attr">toggle</span>: <span class="built_in">boolean</span> = <span class="literal">true</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Column</span>() &#123;</span><br><span class="line">      <span class="title class_">Button</span>(<span class="string">&#x27;click me&#x27;</span>)</span><br><span class="line">        <span class="comment">// 执行动画：从起点移动到(300,200)，再到(300,500)，再到终点</span></span><br><span class="line">        .<span class="title function_">motionPath</span>(&#123; <span class="attr">path</span>: <span class="string">&#x27;Mstart.x start.y L300 200 L300 500 l500 500 lend.x end.y&#x27;</span>, <span class="attr">from</span>: <span class="number">0.0</span>, <span class="attr">to</span>: <span class="number">1.0</span>, <span class="attr">rotatable</span>: <span class="literal">false</span> &#125;)</span><br><span class="line">        .<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">          <span class="title function_">animateTo</span>(&#123; <span class="attr">duration</span>: <span class="number">4000</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span> &#125;, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">toggle</span> = !<span class="variable language_">this</span>.<span class="property">toggle</span> <span class="comment">// 通过this.toggle变化组件的位置</span></span><br><span class="line">          &#125;)</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">alignItems</span>(<span class="variable language_">this</span>.<span class="property">toggle</span> ? <span class="title class_">HorizontalAlign</span>.<span class="property">Start</span> : <span class="title class_">HorizontalAlign</span>.<span class="property">End</span>)</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h2 id="转场动画"><a href="#转场动画" class="headerlink" title="转场动画"></a>转场动画</h2><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">转场动画分为页面转场、组件内转场和共享元素转场三种</span><br></pre></td></tr></table></figure>

<h3 id="页面间转场动画"><a href="#页面间转场动画" class="headerlink" title="页面间转场动画"></a><a target="_blank" rel="noopener" href="https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V2/ts-page-transition-animation-0000001477981233-V2">页面间转场动画</a></h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">在全局pageTransition方法内配置页面入场和页面退场时的自定义转场动效。</span><br></pre></td></tr></table></figure>

<h4 id="转场动画函数"><a href="#转场动画函数" class="headerlink" title="转场动画函数"></a>转场动画函数</h4><ul>
<li><p>pageTransition</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pageTransition?(): void</span><br><span class="line">进入此页面或移动到其他页面时实现动画。</span><br></pre></td></tr></table></figure></li>
<li><p>PageTransitionEnter</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">PageTransitionEnter(value: PageTransitionOptions)</span><br><span class="line">设置当前页面的自定义入场动效。</span><br></pre></td></tr></table></figure></li>
<li><p>PageTransitionExit</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">PageTransitionExit(value: PageTransitionOptions)</span><br><span class="line">设置当前页面的自定义入场动效。</span><br></pre></td></tr></table></figure></li>
</ul>
<h4 id="示例-4"><a href="#示例-4" class="headerlink" title="示例"></a>示例</h4><ul>
<li>页面1</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">struct <span class="title class_">PageTransitionPage2</span> &#123;</span><br><span class="line">  <span class="meta">@State</span> <span class="attr">active</span>: <span class="built_in">boolean</span> = <span class="literal">false</span></span><br><span class="line">  <span class="meta">@State</span> <span class="attr">scale2</span>: <span class="built_in">number</span> = <span class="number">1</span></span><br><span class="line">  <span class="meta">@State</span> <span class="attr">opacity2</span>: <span class="built_in">number</span> = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Column</span>() &#123;</span><br><span class="line"></span><br><span class="line">        <span class="title class_">Image</span>($r(<span class="string">&#x27;app.media.2&#x27;</span>)).<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">          router.<span class="title function_">pushUrl</span>(&#123;<span class="attr">url</span>:<span class="string">&quot;pages/animation/PageTransitionPage1&quot;</span>&#125;,router.<span class="property">RouterMode</span>.<span class="property">Standard</span>, <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (err) &#123;</span><br><span class="line">              <span class="variable language_">console</span>.<span class="title function_">error</span>(<span class="string">`pushUrl failed, code is <span class="subst">$&#123;err.code&#125;</span>, message is <span class="subst">$&#123;err.message&#125;</span>`</span>);</span><br><span class="line">              <span class="keyword">return</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;pushUrl success&#x27;</span>);</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line">    &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">scale</span>(&#123; <span class="attr">x</span>: <span class="variable language_">this</span>.<span class="property">scale2</span> &#125;).<span class="title function_">opacity</span>(<span class="variable language_">this</span>.<span class="property">opacity2</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 自定义方式1：完全自定义转场过程的效果</span></span><br><span class="line">  <span class="comment">// pageTransition() &#123;</span></span><br><span class="line">  <span class="comment">//   PageTransitionEnter(&#123; duration: 1200, curve: Curve.Linear &#125;)</span></span><br><span class="line">  <span class="comment">//     .onEnter((type: RouteType, progress: number) =&gt; &#123;</span></span><br><span class="line">  <span class="comment">//       this.scale2 = 1</span></span><br><span class="line">  <span class="comment">//       this.opacity2 = progress</span></span><br><span class="line">  <span class="comment">//     &#125;) // 进场过程中会逐帧触发onEnter回调，入参为动效的归一化进度(0% -- 100%)</span></span><br><span class="line">  <span class="comment">//   PageTransitionExit(&#123; duration: 1500, curve: Curve.Ease &#125;)</span></span><br><span class="line">  <span class="comment">//     .onExit((type: RouteType, progress: number) =&gt; &#123;</span></span><br><span class="line">  <span class="comment">//       this.scale2 = 1 - progress</span></span><br><span class="line">  <span class="comment">//       this.opacity2 = 1</span></span><br><span class="line">  <span class="comment">//     &#125;) // 退场过程中会逐帧触发onExit回调，入参为动效的归一化进度(0% -- 100%)</span></span><br><span class="line">  <span class="comment">// &#125;</span></span><br><span class="line">  <span class="comment">// 自定义方式2：使用系统提供的多种默认效果(平移、缩放、透明度等)</span></span><br><span class="line">  <span class="title function_">pageTransition</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">PageTransitionEnter</span>(&#123; <span class="attr">duration</span>: <span class="number">100</span> &#125;)</span><br><span class="line">      .<span class="title function_">slide</span>(<span class="title class_">SlideEffect</span>.<span class="property">Left</span>)</span><br><span class="line">    <span class="title class_">PageTransitionExit</span>(&#123; <span class="attr">delay</span>: <span class="number">0</span> &#125;)</span><br><span class="line">      <span class="comment">// .translate(&#123; x: 100.0, y: 100.0 &#125;)</span></span><br><span class="line">      <span class="comment">// .opacity(0)</span></span><br><span class="line">      .<span class="title function_">slide</span>(<span class="title class_">SlideEffect</span>.<span class="property">Right</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>页面2</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Entry</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line">struct <span class="title class_">PageTransitionPage1</span> &#123;</span><br><span class="line">  <span class="meta">@State</span> <span class="attr">active</span>: <span class="built_in">boolean</span> = <span class="literal">false</span></span><br><span class="line">  <span class="meta">@State</span> <span class="attr">scale1</span>: <span class="built_in">number</span> = <span class="number">1</span></span><br><span class="line">  <span class="meta">@State</span> <span class="attr">opacity1</span>: <span class="built_in">number</span> = <span class="number">1</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Column</span>() &#123;</span><br><span class="line">        <span class="title class_">Image</span>($r(<span class="string">&#x27;app.media.1&#x27;</span>)).<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">          router.<span class="title function_">pushUrl</span>(&#123;<span class="attr">url</span>:<span class="string">&quot;pages/animation/PageTransitionPage2&quot;</span>&#125;,router.<span class="property">RouterMode</span>.<span class="property">Standard</span>, <span class="function">(<span class="params">err</span>) =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (err) &#123;</span><br><span class="line">              <span class="variable language_">console</span>.<span class="title function_">error</span>(<span class="string">`pushUrl failed, code is <span class="subst">$&#123;err.code&#125;</span>, message is <span class="subst">$&#123;err.message&#125;</span>`</span>);</span><br><span class="line">              <span class="keyword">return</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">info</span>(<span class="string">&#x27;pushUrl success&#x27;</span>);</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line">    &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">scale</span>(&#123; <span class="attr">x</span>: <span class="variable language_">this</span>.<span class="property">scale1</span> &#125;).<span class="title function_">opacity</span>(<span class="variable language_">this</span>.<span class="property">opacity1</span>)</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 自定义方式1：完全自定义转场过程的效果</span></span><br><span class="line">  <span class="comment">// pageTransition() &#123;</span></span><br><span class="line">  <span class="comment">//   PageTransitionEnter(&#123; duration: 1200, curve: Curve.Linear &#125;)</span></span><br><span class="line">  <span class="comment">//     .onEnter((type: RouteType, progress: number) =&gt; &#123;</span></span><br><span class="line">  <span class="comment">//       this.scale1 = 1</span></span><br><span class="line">  <span class="comment">//       this.opacity1 = progress</span></span><br><span class="line">  <span class="comment">//     &#125;) // 进场过程中会逐帧触发onEnter回调，入参为动效的归一化进度(0% -- 100%)</span></span><br><span class="line">  <span class="comment">//   PageTransitionExit(&#123; duration: 1500, curve: Curve.Ease &#125;)</span></span><br><span class="line">  <span class="comment">//     .onExit((type: RouteType, progress: number) =&gt; &#123;</span></span><br><span class="line">  <span class="comment">//       this.scale1 = 1 - progress</span></span><br><span class="line">  <span class="comment">//       this.opacity1 = 1</span></span><br><span class="line">  <span class="comment">//     &#125;) // 退场过程中会逐帧触发onExit回调，入参为动效的归一化进度(0% -- 100%)</span></span><br><span class="line">  <span class="comment">// &#125;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 自定义方式2：使用系统提供的多种默认效果(平移、缩放、透明度等)</span></span><br><span class="line">  <span class="title function_">pageTransition</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">PageTransitionEnter</span>(&#123; <span class="attr">duration</span>: <span class="number">500</span> &#125;)</span><br><span class="line">      .<span class="title function_">slide</span>(<span class="title class_">SlideEffect</span>.<span class="property">Left</span>)</span><br><span class="line">    <span class="title class_">PageTransitionExit</span>(&#123; <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">      <span class="comment">// .translate(&#123; x: 100.0, y: 100.0 &#125;)</span></span><br><span class="line">      .<span class="title function_">opacity</span>(<span class="number">0</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="组件内转场动画"><a href="#组件内转场动画" class="headerlink" title="组件内转场动画"></a><a target="_blank" rel="noopener" href="https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V2/ts-transition-animation-component-0000001427902496-V2">组件内转场动画</a></h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">组件内转场主要通过transition属性配置转场参数，在组件插入和删除时显示过渡动效，主要用于容器组件中的子组件插入和删除时，提升用户体验（需要配合animateTo才能生效，动效时长、曲线、延时跟随animateTo中的配置）</span><br></pre></td></tr></table></figure>

<h4 id="属性-4"><a href="#属性-4" class="headerlink" title="属性"></a>属性</h4><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">参数类型</th>
<th align="left">参数描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">transition</td>
<td align="left">TransitionOptions</td>
<td align="left">设置组件插入显示和删除隐藏的过渡效果。默认值：不设置任何过渡效果时，默认有透明度从0到1的过渡效果。若设置了其他过渡效果，以设置的过渡效果为准。<strong>说明：</strong>所有参数均为可选参数，详细描述见TransitionOptions参数说明。</td>
</tr>
</tbody></table>
<h2 id="TransitionOptions参数说明"><a href="#TransitionOptions参数说明" class="headerlink" title="TransitionOptions参数说明"></a>TransitionOptions参数说明</h2><table>
<thead>
<tr>
<th>参数名称</th>
<th>参数类型</th>
<th>必填</th>
<th>参数描述</th>
</tr>
</thead>
<tbody><tr>
<td>type</td>
<td>TransitionType</td>
<td>否</td>
<td>默认包括组件新增和删除。默认值：TransitionType.All 说明：不指定Type时说明插入删除使用同一种效果。</td>
</tr>
<tr>
<td>opacity</td>
<td>number</td>
<td>否</td>
<td>设置组件转场时的透明度效果，为插入时起点和删除时终点的值。默认值：1 取值范围： [0, 1] 说明：设置小于0或大于1的非法值时，按1处理。</td>
</tr>
<tr>
<td>translate</td>
<td>{x? : number ， string,y? : number ， string,z? : number ， string}</td>
<td>否</td>
<td>设置组件转场时的平移效果，为插入时起点和删除时终点的值。-x：横向的平移距离。-y：纵向的平移距离。-z：竖向的平移距离。</td>
</tr>
<tr>
<td>scale</td>
<td>{x? : number,y? : number,z? : number,centerX? : number ， string,centerY? : number ， string}</td>
<td>否</td>
<td>设置组件转场时的缩放效果，为插入时起点和删除时终点的值。-x：横向放大倍数（或缩小比例）。-y：纵向放大倍数（或缩小比例）。-z：当前为二维显示，该参数无效。centerX、centerY指缩放中心点，centerX和centerY默认值是”50%”，中心点为0时，默认的是组件的左上角。</td>
</tr>
<tr>
<td>rotate</td>
<td>{x?: number,y?: number,z?: number,angle: number ， string,centerX?: number ， string,centerY?: number ，string}</td>
<td>否</td>
<td>设置组件转场时的旋转效果，为插入时起点和删除时终点的值。-x：横向的旋转向量。-y：纵向的旋转向量。-z：竖向的旋转向量。centerX,centerY指旋转中心点，centerX和centerY默认值是”50%”。中心点为（0，0）时，默认的是组件的左上角。</td>
</tr>
</tbody></table>
<h4 id="示例-5"><a href="#示例-5" class="headerlink" title="示例"></a>示例</h4><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Entry</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line">struct <span class="title class_">TransitionPage</span> &#123;</span><br><span class="line">  <span class="meta">@State</span> <span class="attr">flag</span>: <span class="built_in">boolean</span> = <span class="literal">true</span></span><br><span class="line">  <span class="meta">@State</span> <span class="attr">show</span>: <span class="built_in">string</span> = <span class="string">&#x27;show&#x27;</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Column</span>() &#123;</span><br><span class="line">      <span class="title class_">Button</span>(<span class="variable language_">this</span>.<span class="property">show</span>).<span class="title function_">width</span>(<span class="number">80</span>).<span class="title function_">height</span>(<span class="number">30</span>).<span class="title function_">margin</span>(<span class="number">30</span>)</span><br><span class="line">        .<span class="title function_">onClick</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">          <span class="comment">// 点击Button控制Image的显示和消失</span></span><br><span class="line">          <span class="title function_">animateTo</span>(&#123; <span class="attr">duration</span>: <span class="number">1000</span> &#125;, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (<span class="variable language_">this</span>.<span class="property">flag</span>) &#123;</span><br><span class="line">              <span class="variable language_">this</span>.<span class="property">show</span> = <span class="string">&#x27;hide&#x27;</span></span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">              <span class="variable language_">this</span>.<span class="property">show</span> = <span class="string">&#x27;show&#x27;</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="variable language_">this</span>.<span class="property">flag</span> = !<span class="variable language_">this</span>.<span class="property">flag</span></span><br><span class="line">          &#125;)</span><br><span class="line">        &#125;)</span><br><span class="line">      <span class="keyword">if</span> (<span class="variable language_">this</span>.<span class="property">flag</span>) &#123;</span><br><span class="line">        <span class="comment">// Image的显示和消失配置为不同的过渡效果</span></span><br><span class="line">        <span class="title class_">Image</span>($r(<span class="string">&#x27;app.media.1&#x27;</span>)).<span class="title function_">width</span>(<span class="number">300</span>).<span class="title function_">height</span>(<span class="number">300</span>)</span><br><span class="line">          .<span class="title function_">transition</span>(&#123; <span class="attr">type</span>: <span class="title class_">TransitionType</span>.<span class="property">Delete</span>, <span class="attr">scale</span>: &#123; <span class="attr">x</span>: <span class="number">0</span>, <span class="attr">y</span>: <span class="number">0</span> &#125; &#125;)</span><br><span class="line">          .<span class="title function_">transition</span>(&#123; <span class="attr">type</span>: <span class="title class_">TransitionType</span>.<span class="property">Insert</span>, <span class="attr">rotate</span>: &#123; <span class="attr">angle</span>: <span class="number">180</span> &#125; &#125;)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="共享元素转场动画"><a href="#共享元素转场动画" class="headerlink" title="共享元素转场动画"></a><a target="_blank" rel="noopener" href="https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V2/ts-transition-animation-shared-elements-0000001428061776-V2">共享元素转场动画</a></h3><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">共享元素转场动画指的是组件支持页面间的转场，简单来说就是在页面切换时有一个共享的组件在新旧两个页面之间切换，因为共享的组件在新旧页面上的位置、尺寸等有所差异，所以在页面切换时它会从旧页面逐渐过渡到新页面中的指定位置，这样就会产生了转场动画。当路由进行切换时，可以通过设置组件的 sharedTransition 属性将该元素标记为共享元素并设置对应的共享元素转场动效。</span><br></pre></td></tr></table></figure>

<ul>
<li>sharedTransition(id: string, options?: sharedTransitionOptions): T;</li>
</ul>
<h4 id="属性-5"><a href="#属性-5" class="headerlink" title="属性"></a>属性</h4><p>id：设置共享元素转场动画的唯一标识，两个页面的组件配置为同一个id，则转场过程中会进行共享元素转场，配置为空字符串时不会有共享元素转场效果。</p>
<p>options：设置共享元素转场动画的配置参数， sharedTransitionOptions 参数说明如下：</p>
<p>duration：设置动画的执行时长，单位为毫秒，默认为 1000 毫秒。<br>curve：设置动画曲线，默认值为 Linear。<br>delay：设置动画的延迟执行时长，单位为毫秒，默认为 0 不延迟。<br>motionPath：自定义动画路径。<br>type：设置动画类型。</p>
<h4 id="示例-6"><a href="#示例-6" class="headerlink" title="示例"></a>示例</h4><ul>
<li>页面1</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">&#x27;@ohos.router&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="meta">@Entry</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line">struct <span class="title class_">SharedTransitionPage1</span> &#123;</span><br><span class="line">  <span class="meta">@State</span> <span class="attr">message</span>: <span class="built_in">string</span> = <span class="string">&#x27;Hello World&#x27;</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Row</span>() &#123;</span><br><span class="line">      <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.stop&quot;</span>)).<span class="title function_">width</span>(<span class="number">40</span>).<span class="title function_">height</span>(<span class="number">40</span>).<span class="title function_">sharedTransition</span>(<span class="string">&quot;stop&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">      <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.play&quot;</span>)).<span class="title function_">width</span>(<span class="number">40</span>).<span class="title function_">height</span>(<span class="number">40</span>).<span class="title function_">sharedTransition</span>(<span class="string">&quot;play&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">        .<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">          router.<span class="title function_">pushUrl</span>(&#123;<span class="attr">url</span>:<span class="string">&quot;pages/animation/SharedTransitionPage2&quot;</span>&#125;,router.<span class="property">RouterMode</span>.<span class="property">Standard</span>)</span><br><span class="line">        &#125;)</span><br><span class="line">      <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.pause&quot;</span>)).<span class="title function_">width</span>(<span class="number">40</span>).<span class="title function_">height</span>(<span class="number">40</span>).<span class="title function_">sharedTransition</span>(<span class="string">&quot;pause&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">    &#125;.<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">justifyContent</span>(<span class="title class_">FlexAlign</span>.<span class="property">Center</span>)</span><br><span class="line">    .<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>页面2</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> router <span class="keyword">from</span> <span class="string">&#x27;@ohos.router&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="meta">@Entry</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line">struct <span class="title class_">SharedTransitionPage2</span> &#123;</span><br><span class="line">  <span class="meta">@State</span> <span class="attr">message</span>: <span class="built_in">string</span> = <span class="string">&#x27;Hello World&#x27;</span></span><br><span class="line"></span><br><span class="line">  <span class="title function_">build</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="title class_">Column</span>()&#123;</span><br><span class="line">      <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.play&quot;</span>)).<span class="title function_">width</span>(<span class="number">140</span>).<span class="title function_">height</span>(<span class="number">140</span>).<span class="title function_">margin</span>(&#123;<span class="attr">bottom</span>:<span class="number">40</span>,<span class="attr">top</span>:<span class="number">50</span>&#125;) .<span class="title function_">onClick</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">        router.<span class="title function_">pushUrl</span>(&#123;<span class="attr">url</span>:<span class="string">&quot;pages/animation/SharedTransitionPage1&quot;</span>&#125;,router.<span class="property">RouterMode</span>.<span class="property">Standard</span>)</span><br><span class="line">      &#125;).</span><br><span class="line">      <span class="title function_">sharedTransition</span>(<span class="string">&quot;play&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">      <span class="title class_">Row</span>() &#123;</span><br><span class="line">        <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.stop&quot;</span>)).<span class="title function_">width</span>(<span class="number">80</span>).<span class="title function_">height</span>(<span class="number">80</span>).<span class="title function_">sharedTransition</span>(<span class="string">&quot;stop&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">        <span class="title class_">Blank</span>()</span><br><span class="line">        <span class="title class_">Image</span>($r(<span class="string">&quot;app.media.pause&quot;</span>)).<span class="title function_">width</span>(<span class="number">80</span>).<span class="title function_">height</span>(<span class="number">80</span>).<span class="title function_">sharedTransition</span>(<span class="string">&quot;pause&quot;</span>, &#123; <span class="attr">duration</span>: <span class="number">800</span>, <span class="attr">curve</span>: <span class="title class_">Curve</span>.<span class="property">Linear</span>, <span class="attr">delay</span>: <span class="number">100</span> &#125;)</span><br><span class="line">      &#125;.<span class="title function_">width</span>(<span class="string">&#x27;80%&#x27;</span>).<span class="title function_">justifyContent</span>(<span class="title class_">FlexAlign</span>.<span class="property">Center</span>)</span><br><span class="line">      .<span class="title function_">height</span>(<span class="string">&#x27;100%&#x27;</span>)</span><br><span class="line">    &#125; .<span class="title function_">width</span>(<span class="string">&#x27;100%&#x27;</span>).<span class="title function_">justifyContent</span>(<span class="title class_">FlexAlign</span>.<span class="property">Center</span>)</span><br><span class="line">    .<span class="title function_">height</span>(<span class="string">&#x27;70%&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog">侯玉东</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog/2024/03/18/harmonyOS/%E5%8A%A8%E7%94%BB/">https://houyudong1989.gitee.io/blog/2024/03/18/harmonyOS/%E5%8A%A8%E7%94%BB/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://houyudong1989.gitee.io/blog" target="_blank">East'blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/harmonyOS/">harmonyOS</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/library1.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2024/03/21/harmonyOS/stage%E6%A8%A1%E5%9E%8B/" title="stage模型"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">stage模型</div></div></a></div><div class="next-post pull-right"><a href="/blog/2024/03/01/python/1%E3%80%81%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" title="正则表达式"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">正则表达式</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2024/01/20/harmonyOS/ArkUI-X/" title="ArkUI-X"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-01-20</div><div class="title">ArkUI-X</div></div></a></div><div><a href="/blog/2023/12/15/harmonyOS/Canvas%E7%BB%98%E5%88%B6%E6%8A%98%E7%BA%BF%E5%9B%BE/" title="canvas绘制折线图"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-15</div><div class="title">canvas绘制折线图</div></div></a></div><div><a href="/blog/2023/12/02/harmonyOS/Canvas%E7%BB%98%E5%88%B6%E6%9F%B1%E7%8A%B6%E5%9B%BE/" title="canvas绘制柱状图"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-02</div><div class="title">canvas绘制柱状图</div></div></a></div><div><a href="/blog/2024/03/25/harmonyOS/commonevent%E3%80%81eventhub%E3%80%81emitter%E5%92%8Cworker%E4%BD%BF%E7%94%A8/" title="commonevent、eventhub、emitter和worker使用"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-03-25</div><div class="title">commonevent、eventhub、emitter和worker使用</div></div></a></div><div><a href="/blog/2023/11/05/harmonyOS/hdc/" title="hdc 使用帮助"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-11-05</div><div class="title">hdc 使用帮助</div></div></a></div><div><a href="/blog/2023/12/26/harmonyOS/router%E8%B7%AF%E7%94%B1/" title="router路由跳转"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-26</div><div class="title">router路由跳转</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/blog/img/head.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">侯玉东</div><div class="author-info__description">生命不息，奋斗不止</div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/houyudong1989"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/houyudong1989" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:420098321@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎来到我的博客！！！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8A%A8%E7%94%BB%E6%A6%82%E8%BF%B0"><span class="toc-number">1.</span> <span class="toc-text">动画概述</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%A7%E5%8A%A8%E7%94%BB"><span class="toc-number">1.1.</span> <span class="toc-text">帧动画</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7"><span class="toc-number">1.1.1.</span> <span class="toc-text">属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ImageFrameInfo%E5%AF%B9%E8%B1%A1%E8%AF%B4%E6%98%8E"><span class="toc-number">1.1.2.</span> <span class="toc-text">ImageFrameInfo对象说明</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6"><span class="toc-number">1.1.3.</span> <span class="toc-text">事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#FillMode"><span class="toc-number">1.1.4.</span> <span class="toc-text">FillMode</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#AnimationStatus"><span class="toc-number">1.1.5.</span> <span class="toc-text">AnimationStatus</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B"><span class="toc-number">1.1.6.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%98%BE%E5%BC%8F%E5%8A%A8%E7%94%BB"><span class="toc-number">1.2.</span> <span class="toc-text">显式动画</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7-1"><span class="toc-number">1.2.1.</span> <span class="toc-text">属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#AnimateParam%E5%AF%B9%E8%B1%A1%E8%AF%B4%E6%98%8E"><span class="toc-number">1.2.2.</span> <span class="toc-text">AnimateParam对象说明</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-1"><span class="toc-number">1.2.3.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7%E5%8A%A8%E7%94%BB"><span class="toc-number">1.3.</span> <span class="toc-text">属性动画</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7-2"><span class="toc-number">1.3.1.</span> <span class="toc-text">属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-2"><span class="toc-number">1.3.2.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B7%AF%E5%BE%84%E5%8A%A8%E7%94%BB"><span class="toc-number">1.4.</span> <span class="toc-text">路径动画</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7-3"><span class="toc-number">1.4.1.</span> <span class="toc-text">属性</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-3"><span class="toc-number">1.4.2.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB"><span class="toc-number">1.5.</span> <span class="toc-text">转场动画</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E9%97%B4%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB"><span class="toc-number">1.5.1.</span> <span class="toc-text">页面间转场动画</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB%E5%87%BD%E6%95%B0"><span class="toc-number">1.5.1.1.</span> <span class="toc-text">转场动画函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-4"><span class="toc-number">1.5.1.2.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E5%86%85%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB"><span class="toc-number">1.5.2.</span> <span class="toc-text">组件内转场动画</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7-4"><span class="toc-number">1.5.2.1.</span> <span class="toc-text">属性</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#TransitionOptions%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E"><span class="toc-number">1.6.</span> <span class="toc-text">TransitionOptions参数说明</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-5"><span class="toc-number">1.6.0.1.</span> <span class="toc-text">示例</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B1%E4%BA%AB%E5%85%83%E7%B4%A0%E8%BD%AC%E5%9C%BA%E5%8A%A8%E7%94%BB"><span class="toc-number">1.6.1.</span> <span class="toc-text">共享元素转场动画</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B1%9E%E6%80%A7-5"><span class="toc-number">1.6.1.1.</span> <span class="toc-text">属性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%A4%BA%E4%BE%8B-6"><span class="toc-number">1.6.1.2.</span> <span class="toc-text">示例</span></a></li></ol></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="字符和字符串"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串">字符和字符串</a><time datetime="2024-05-06T11:15:27.280Z" title="发表于 2024-05-06 19:15:27">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="指针和函数指针"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针">指针和函数指针</a><time datetime="2024-05-06T11:14:29.047Z" title="发表于 2024-05-06 19:14:29">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="m3u8格式"/></a><div class="content"><a class="title" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式">m3u8格式</a><time datetime="2024-05-05T01:43:26.865Z" title="发表于 2024-05-05 09:43:26">2024-05-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="charles 抓包"/></a><div class="content"><a class="title" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包">charles 抓包</a><time datetime="2024-04-30T06:49:29.279Z" title="发表于 2024-04-30 14:49:29">2024-04-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="playwright"/></a><div class="content"><a class="title" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright">playwright</a><time datetime="2024-04-26T07:30:36.069Z" title="发表于 2024-04-26 15:30:36">2024-04-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 侯玉东</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><div class="aplayer no-destroy" data-id="8873950678" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener
  btf.removeGlobalFnEvent('pjax')
  btf.removeGlobalFnEvent('themeChange')

  document.getElementById('rightside').classList.remove('rightside-show')
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', e => {
  if (e.request.status === 404) {
    pjax.loadUrl('/blog/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>